package com.wson.model.compass.transaction.impl;

import com.wson.model.basic.IMarkableField;
import com.wson.model.basic.PersistenceType;
import com.wson.model.clouddisk.transaction.impl.CodiskTransactionModel;
import com.wson.model.compass.transaction.ICompassTransactionManip;
import com.wson.model.compass.transaction.ICompassTransactionMeta;
import com.wson.model.compass.transaction.ICompassTransactionView;
import com.wson.util.throwable.BasicException;

public class CompassTransactionModel extends CodiskTransactionModel
	implements ICompassTransactionManip, ICompassTransactionView{



	
	@IMarkableField(Attribute=ATTR_SRCIDENTITYID, Syntax=SYNC_SRCIDENTITYID)	
	private  Long srcIdentityID;
	
	private  String srcIdentityName;

	
	@IMarkableField(Attribute=ATTR_DESTIDENTITYID, Syntax=SYNC_DESTIDENTITYID)	
	private  Long destIdentityID;

	private  String destIdentityName;

	
	@Override
	public String getSync() {
		return ICompassTransactionMeta.SYNC_SELF;
	}


	@Override
	public Long getMetaID() {
		return ICompassTransactionMeta.META_ID;
	}



	public String getSrcIdentityName() {
		return srcIdentityName;
	}


	public void setSrcIdentityName(String srcIdentityName) {
		this.srcIdentityName = srcIdentityName;
	}

	public Long getSrcIdentityID() {
		return srcIdentityID;
	}


	public void setSrcIdentityID(Long srcIdentityID) {
		this.srcIdentityID = srcIdentityID;
	}


	public Long getDestIdentityID() {
		return destIdentityID;
	}


	public void setDestIdentityID(Long destIdentityID) {
		this.destIdentityID = destIdentityID;
	}


	public String getDestIdentityName() {
		return destIdentityName;
	}


	public void setDestIdentityName(String destIdentityName) {
		this.destIdentityName = destIdentityName;
	}


	@Override
	public PersistenceType getPersistenceType() {
		return PersistenceType.REST;
	}


	

	@Override
	public String getAttributeValue(long attribute_id) {
		if(attribute_id==ATTR_SERVERNODEPATTERN)
			return this.getSrcIdentityName().substring(
					this.getSrcIdentityName().indexOf("@")+1
					, this.getSrcIdentityName().indexOf(".", this.getSrcIdentityName().indexOf("@")+1));
		return super.getAttributeValue(attribute_id);
	}

	
	
	
	
	

	@Override
	public String getSrcCloudPath() {
		if(super.getSrcCloudPath()==null){
			String path = this.getShortText()+"//"+this.getSrcIdentityName()+"//";
			super.setSrcCloudPath(path);
		}
		return super.getSrcCloudPath();
	}



	@Override
	public String getDestCloudPath() {
		if(super.getDestCloudPath()==null){
			String path = this.getShortText()+"//"+this.getDestIdentityName()+"//";
			super.setDestCloudPath(path);
		}
		return super.getDestCloudPath();
	}


	@Override
	public void selfCreate() throws BasicException {
		
		super.selfCreate();
	}

	

}
